package com.zego.wawaji.ui.rank.virtual;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.toast.PToast;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.third.image.ImageLoader;
import com.zego.wawaji.ui.base.BaseAppCompatActivity;
import com.zego.wawaji.ui.rank.bean.Award;

/**
 * 虚拟商品
 * Created by Su on 2018/1/10.
 */
public class VirtualPrizeActivity extends BaseAppCompatActivity implements View.OnClickListener {
    private EditText edtCount;
    private Award award;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.virtual_prize_act);
        initView();
    }

    private void initView() {
        setBackView();
        setTitle("填写订单");
        award = getIntent().getParcelableExtra("award");
        if (award == null) {
            PToast.showShort("商品信息获取失败");
            finish();
        }

        edtCount = (EditText) findViewById(R.id.edt_count);
        findViewById(R.id.send_all).setOnClickListener(this);

        ImageView virtualIcon = (ImageView) findViewById(R.id.virtual_icon);
        ImageLoader.loadRoundCenterCrop(this, award.getAwardImg(), virtualIcon);
        TextView virtualName = (TextView) findViewById(R.id.virtual_name);
        TextView describeInfo = (TextView) findViewById(R.id.describe_info);
        virtualName.setText(award.getAwardName());
        describeInfo.setText(award.getAwardRemark());

        LinearLayout prizeRemark = (LinearLayout) findViewById(R.id.prize_remark);
        TextView remark = (TextView) findViewById(R.id.remark);
        if (TextUtils.isEmpty(award.getRemark())) {
            prizeRemark.setVisibility(View.GONE);
        } else {
            remark.setText(award.getRemark());
        }
    }

    @Override
    public int[] hideSoftByEditViewIds() {
        int[] ids = {R.id.edt_count};
        return ids;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.send_all:
                String acount = edtCount.getText().toString();
                if (TextUtils.isEmpty(acount)) {
                    PToast.showShort("请输入充值账号");
                    return;
                }
                ModuleMgr.getWawaMgr().reqAwardRechange(award.getId(), acount, response -> {
                    if (response.isOk()) {
                        finish();
                    }
                });
                break;
        }
    }
}
